
clear all
set maxvar 10000 
set more off   
set scheme s1color


*global dir D:\Dati\Profili\b724170\Documents\Dropbox\CreditFlows\Evidence\EventStudy
*global dir C:\Users\Michelacci\Dropbox\CreditFlows\Evidence\EventStudy
*global dir $apath\CreditFlows\Evidence\EventStudy
cd $dir



use  "$data/Table3_dataset.dta", clear


*label variable employment_perce  "Employment  over avg. $ \times 10^4$"
***************************************************************************************
*First regression
reghdfe bankdebt  subsi_post dummy_1st dummy_2nd , absorb(  ym id)  cluster(id#dummy_2nd)
*local R2= e(r2)
local R2:  di %13.2fc e(r2)
sleep 500
outreg2 using "$tables/EventSubsidy.tex", replace tex(fragment) nocons label nor2 keep(subsi_post) ///
 bdec(2) rdec(2) addtext($ R^2$, `R2', Firm dummy, "Y", Year-Month dummy, "Y", Reimbursement dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2)   nonotes

/*
*Second regression
*reghdfe D$vary1   subsi_post dummy_1st dummy_2nd , absorb(  ym id)  cluster(id#dummy_2nd)
reghdfe bankdebt  subsi_post_1st subsi_post_2nd dummy_1st dummy_2nd  , absorb(  ym id)  cluster(id#dummy_2nd)
local R2:  di %13.2fc e(r2)
sleep 500
outreg2 using "$tables/EventSubsidy.tex", append tex(fragment) nocons label nor2 keep(subsi_post_1st subsi_post_2nd) sortvar(subsi_post subsi_post_1st subsi_post_2nd) ///
 bdec(2) rdec(2) addtext($ R^2$, `R2', Firm dummy, "Y", Year-Month dummy, "Y", Reimbursement dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2)   nonotes
*/


/*Third regression
*reghdfe bankdebt   EX0  EXp1 EXp2 EXp3 EXp4_res   dummy_1st dummy_2nd , absorb(  ym id)  cluster(id#dummy_2nd)
*outreg2 using "$tables/EventSubsidy.tex", append tex(fragment) nocons label nor2 keep(EX0  EXp1 EXp2 EXp3 EXp4_res) sortvar(subsi_post subsi_post_1st subsi_post_2nd EX0  EXp1 EXp2 EXp3 EXp4_res) ///
*/
reghdfe bankdebt   EX0  EXp1 EXp2 EXp3_res   dummy_1st dummy_2nd , absorb(  ym id)  cluster(id#dummy_2nd)
local R2:  di %13.2fc e(r2)
sleep 500
outreg2 using "$tables/EventSubsidy.tex", append tex(fragment) nocons label nor2 keep(EX0  EXp1 EXp2 EXp3_res) sortvar(subsi_post subsi_post_1st subsi_post_2nd EX0  EXp1 EXp2 EXp3_res) ///
 bdec(2) rdec(2) addtext($ R^2$, `R2', Firm dummy, "Y", Year-Month dummy, "Y", Reimbursement dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2)   nonotes


 
*Fourth regression
reghdfe employment  subsi_post dummy_1st dummy_2nd , absorb(ym id)  cluster(id#dummy_2nd)
local R2:  di %13.2fc e(r2)
sleep 500
outreg2 using "$tables/EventSubsidy.tex", append tex(fragment) nocons label nor2 keep(subsi_post) sortvar(subsi_post subsi_post_1st subsi_post_2nd EX0  EXp1 EXp2_res) ///
 bdec(2) rdec(2) addtext($ R^2$, `R2', Firm dummy, "Y", Year-Month dummy, "Y", Reimbursement dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2)   nonotes

/*
*Fifth regression
*reghdfe D$vary1   subsi_post dummy_1st dummy_2nd , absorb(  ym id)  cluster(id#dummy_2nd)
reghdfe employment  subsi_post_1st subsi_post_2nd dummy_1st dummy_2nd  , absorb(  ym id)  cluster(id#dummy_2nd)
local R2:  di %13.2fc e(r2)
sleep 500
outreg2 using "$tables/EventSubsidy.tex", append tex(fragment) nocons label nor2 keep(subsi_post_1st subsi_post_2nd) sortvar(subsi_post subsi_post_1st subsi_post_2nd EX0  EXp1 EXp2_res) ///
 bdec(2) rdec(2) addtext($ R^2$, `R2', Firm dummy, "Y", Year-Month dummy, "Y", Reimbursement dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2)   nonotes
*/


/*Sixth regression
*reghdfe employment   EX0  EXp1 EXp2 EXp3 EXp4_res   dummy_1st dummy_2nd , absorb(  ym id)  cluster(id#dummy_2nd)
*outreg2 using "$tables/EventSubsidy.tex", append tex(fragment) nocons label nor2 keep(EX0  EXp1 EXp2 EXp3 EXp4_res) sortvar(subsi_post subsi_post_1st subsi_post_2nd EX0  EXp1 EXp2 EXp3 EXp4_res) ///
*/
reghdfe employment   EX0  EXp1 EXp2 EXp3_res  dummy_1st dummy_2nd , absorb(  ym id)  cluster(id#dummy_2nd)	
local R2:  di %13.2fc e(r2)
sleep 500
outreg2 using "$tables/EventSubsidy.tex", append tex(fragment) nocons label nor2 keep(EX0  EXp1 EXp2 EXp3_res) sortvar(subsi_post subsi_post_1st subsi_post_2nd EX0  EXp1 EXp2 EXp3_res) ///
 bdec(2) rdec(2) addtext($ R^2$, `R2', Firm dummy, "Y", Year-Month dummy, "Y", Reimbursement dummy, "Y") /// 
alpha(0.01, 0.05, 0.10) symbol(***,**, *) sdec(2)   nonotes 


***************************************************************************************
*DESCRIPTIVE STATISTICS
gen Age=(ym-ym_nascita)/12
bys codfisc: egen totdip=max(dip)
drop if totdip==0
format ym %tm 
*distinct codfisc if totrate==1

//rename totrate _totrate
//bys codfisc: egen totrate=mean(_totrate)

replace reimbursement=. if reimbursement==0
label var bankdebt "Bank debt, $10^4$\euro "
label var dip "N. of employees "
label var totdip "N. of employees "
label var reimbursement "Reimbursement, $10^4$\euro "
label var totrate "N. of reimbursements"
*label var FinBancario "Bank funding"

*--------------------------------*
*   Prepare data for tex table   *
*--------------------------------*
 gen date = dofm(ym)
format date %d
gen year=year(date)
label var year "Year"

/*
eststo tab1: quietly estpost summarize ///
    Age bankdebt totdip totrate reimbursement , d
*/
/*
eststo tab1: estpost summarize ///
    Age bankdebt totdip totrate reimbursement , d
*/
eststo tab1: estpost summarize ///
    Age bankdebt totdip reimbursement , d
    
* esttab    tab1 using $tables/descriptives.tex, cells("mean(fmt(1)) sd(fmt(1)) p25(fmt(1)) p50(fmt(1))   p75(fmt(1)) count(fmt(0)) ") ///
* collabels("Mean" "SD" "p25" "p50" "p75" "N. obs.") nomtitles nonumbers label  noobs compress replace fragment
 

 esttab    tab1 using $tables/descriptives.tex, cells("mean(fmt(1)) sd(fmt(1)) p50(fmt(1))   count(fmt(0)) ") ///
 collabels("Mean" "SD"  "Median"  "N. obs.") nomtitles nonumbers label  noobs compress replace fragment
 

*FINE
 
